package top.hmtools.jsCss.common;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * 通用基础controller
 * <br>提供优雅的获取request、response、session、requestParams 对象实例公共方法
 * @author HyboWork
 *
 */
public abstract class BaseController {

	/**
	 * 日志对象实例
	 */
	protected Logger logger = LoggerFactory.getLogger(this.getClass());
	
	/**
	 * 获取线程安全的当前请求的HttpServletRequest对象实例
	 * @return
	 */
	protected HttpServletRequest getRequest(){
		return ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
	}
	
	/**
	 * 获取线程安全HttpServletResponse对象实例
	 * @return
	 */
	protected HttpServletResponse getResponse(){
		return ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getResponse();
	}
	
	/**
	 * 获取当前请求的session对象实例
	 * @return
	 */
	protected HttpSession getSession(){
		return this.getRequest().getSession();
	}
	
	/**
	 * 获取请求参数集合
	 * @return
	 */
	protected Map<String, String[]> getParams(){
		return this.getRequest().getParameterMap();
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
